# $Id$
# Maintainer (ArchLinux): Vesa Kaihlavirta <vegai@iki.fi>
# Maintainer (ArchLinux): Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_realname=quassel
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.12.2
pkgrel=3
pkgdesc="Next-generation distributed IRC client (mingw-w64)"
arch=('any')
url="http://quassel-irc.org/"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-qca-qt5-git"
         #"${MINGW_PACKAGE_PREFIX}-extra-cmake-modules" #TODO: only needed with WITH_KDE=ON
         "${MINGW_PACKAGE_PREFIX}-Snorenotify")
source=(http://quassel-irc.org/pub/${_realname}-${pkgver}.tar.bz2
        "0001-MinGW-w64-Adopt-FHS-Layout.patch"
        "0002-Include-QDataStream-in-peer.h.patch"
        "0003-Fix-Q_ASSERT-scopes.patch"
        "0004-use-pkg-config-mingw.patch")
sha256sums=('6bd6f79ecb88fb857bea7e89c767a3bd0f413ff01bae9298dd2e563478947897'
            '12b82e72c2d3a42872104906bad73f48c9b944506d086c0bcd710af904c9fcd8'
            '2cd9ba35f7857f7bc1bd3f9870d5a2b0e091ce8e99839a8c3f2727ef4990689c'
            '6becd9f82ca9b2a22ecf39fd85c93ffa354c63421d6222800b8fb809e50a104a'
            '0e5d8f78d4f3009b88f536040b659436d67a94975718c1cf973530b79993ab70')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-MinGW-w64-Adopt-FHS-Layout.patch
  patch -p1 -i "${srcdir}"/0002-Include-QDataStream-in-peer.h.patch
  patch -p1 -i "${srcdir}"/0003-Fix-Q_ASSERT-scopes.patch
  patch -p1 -i "${srcdir}"/0004-use-pkg-config-mingw.patch
}

build() {
  cd "${srcdir}"
  [ -d build-${CARCH} ] && rm -rf build-${CARCH}
  mkdir build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  # -DWIN32_LEAN_AND_MEAN=1 because "interface" is used in:
  # /mingw64/include/QtDBus/qdbusconnection.h

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_CXX_FLAGS="${CFLAGS} -DWIN32_LEAN_AND_MEAN=1" \
    -DUSE_QT5=ON \
    -DWITH_KDE=OFF \
    -DCMAKE_BUILD_TYPE="Release" \
    -DWANT_CORE=ON \
    -DWANT_QTCLIENT=ON \
    -DWANT_MONO=ON \
    -Wno-dev \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR=${pkgdir} install
}
